package com.lysj.admin.master.bussiness.company.company.controller;

import com.lysj.admin.master.bussiness.company.company.domain.Company;
import com.lysj.admin.master.bussiness.company.company.dto.CompanyQueryDto;
import com.lysj.admin.master.bussiness.company.company.mapper.CompanyMapper;
import com.lysj.admin.master.bussiness.company.company.service.CompanyService;
import com.lysj.admin.master.common.CommonConstant;
import com.lysj.admin.master.common.annotation.MyList;
import com.lysj.admin.master.common.spring.mpbase.MyController;
import com.lysj.admin.master.common.spring.mpbase.MyService;
import com.lysj.admin.master.common.spring.pagination.PageRequestDTO;
import com.lysj.admin.master.common.web.Resp;
import com.lysj.admin.master.common.web.RespUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

/**
 * @author Created by drj on 2020-01-06 14:15
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/company/company")
public class CompanyController extends MyController<CompanyMapper, Company, PageRequestDTO> {

    @Resource
    private CompanyService companyService;

    @Override
    public MyService<CompanyMapper, Company> getService() {
        return companyService;
    }

    /*
     * @author Created by drj on 2020/1/7 11:22
     * @Description ：服务商获取用工企业列表
     */
    @Override
    @MyList
    public Resp list(PageRequestDTO condition) {
        return super.list(condition);
    }

    /*
     * @author Created by drj on 2020/1/7 11:22
     * @Description :代理商获取用工企业列表
     */
    @GetMapping("/find_by_agent")
    public Resp findByAgent(CompanyQueryDto condition) {
        //获取当前登录代理商
        String agentId = getJwtProperty(CommonConstant.AGENT_ID_NAME);
        condition.setAgentId(agentId);
        return super.list(condition);
    }


    @PostMapping("/save_company")
    public Resp saveCompany(Company model, String password) {
        String agentId = getJwtProperty(CommonConstant.AGENT_ID_NAME);
        companyService.saveCompany(model, agentId, password);
        return RespUtil.success("添加客户成功,手机号是客户登录账号");
    }


}
